﻿using System;
using System.Collections;

namespace WorldIndex.Modules.Countries
{
    public class CountriesEnum : IEnumerator
    {
        public Country[] _countries;

        // Enumerators are positioned before the first element
        // until the first MoveNext() call.
        int position = -1;

        public CountriesEnum(Country[] list)
        {
            _countries = list;
        }

        public bool MoveNext()
        {
            position++;
            return (position < _countries.Length);
        }

        public void Reset()
        {
            position = -1;
        }

        public object Current
        {
            get
            {
                try
                {
                    return _countries[position];
                }
                catch (IndexOutOfRangeException)
                {
                    throw new InvalidOperationException();
                }
            }
        }
    }
}
